{% extends 'base/base.html' %}
{% set active_page = active_page|default('manage') -%}

{% block content %}
    {{ super() }}
    <h2 class="sub-header">投放管理</h2>
    <form action="{{ url_for('vipadmin.manage_search') }}" method="get" class="form-inline">
    {% if g.user.is_superuser %}
        <div class="form-group">
            <button type="button" class="btn btn-danger btn-primary"><a
                    href="{{ url_for('vipadmin.manage_add') }}"
                    style="color: white">新增</a></button>
        </div>
    {% endif -%}

        <div class="form-group">
            <input type="text" class="form-control" name="q" placeholder="正在投放的链接或者微信号...">
        </div>
        <div class="form-group">
            <button type="submit" class="btn btn-default btn-primary">搜索</button>
        </div>
    </form>
    <div class="table-responsive">
        <table class="table table-striped table-hover">
            <thead>
            <tr>
                <th>ID</th>
                <th>投放域名</th>
                <th>投放微信</th>
                <th>投放模板</th>
                <th>CNZZ号</th>
                <th>备注</th>
                <th colspan="3">操作</th>
            </tr>
            </thead>
            <tbody>


            {% for page in page_data.items %}
                <tr>
                    <td>{{ page.tid }}</td>
                    <td>{{ page.web_url }}</td>
                    <td>{{ page.wechat }}</td>
                    <td>{{ page.manage }}</td>
                    <td>{{ page.cnzz }}</td>
                    <td>{{ page.remark }}</td>


                    <td colspan="3">
                        <a href="{{ page.web_url }}" class="btn btn-default btn-lg btn-sm" role="button"
                           target="_blank">查看</a>
                        <a href="{{ url_for('vipadmin.manage_edit', tid=page.tid) }}"
                           class="btn btn-default btn-lg btn-sm" role="button">修改</a>
                        {% if g.user.is_superuser %}
                            <a class="btn btn-default btn-lg btn-sm btn-danger" role="button" data-toggle="modal"
                               data-href='{{ url_for('vipadmin.manage_delete', tid=page.tid) }}'
                               data-target="#confirm-delete">删除</a>
                        {% endif %}
                    </td>
                </tr>
            {% endfor -%}
            </tbody>
        </table>
    </div>


    <!-- 分页 -->
    <nav aria-label="Page navigation" class="pull-right">

        {% set name=request.args.get('name', '') %}
        <ul class="pagination">
            {% if page_data.has_prev %}
                <li>
                    <a href="{{ url_for('vipadmin.manage_search', page=page_data.prev_num) }}&q={{ q }}" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
            {% else %}
                <li class="disabled">
                    <a href="javascript:void(0)" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
            {% endif -%}
            {% for page_num in page_data.iter_pages() %}
                <li><a href="{{ url_for('vipadmin.manage_search', page=page_num) }}&q={{ q }}">{{ page_num }}</a></li>
            {% endfor -%}
            {% if page_data.has_next %}
                <li>
                    <a href="{{ url_for('vipadmin.manage_search', page=page_data.next_num) }}&q={{ q }}" aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
            {% else %}
                <li class="disabled">
                    <a href="javascript:void(0)" aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
            {% endif -%}
        </ul>
        <p class="text-center">总共{{ page_data.pages }}页；总共{{ page_data.total }}条记录</p>
    </nav>
{% endblock -%}